<template>
    <div class="tabs mui-flex aic jcc">
        <div v-for="(item,index) in tabs"
             :key="index"
             :class="{active: item.code === activeTabsCode}"
             @click="tabChange(item.path)">{{item.text}}</div>
        <div class="operate">
            <el-dropdown @command="operateHandle">
                <span class="el-dropdown-link">
                    <i class="el-icon-setting"></i>
                </span>
                <el-dropdown-menu slot="dropdown">
                    <el-dropdown-item command="logout">退出登录</el-dropdown-item>
                </el-dropdown-menu>
            </el-dropdown>
        </div>
    </div>
</template>

<script>
export default {
    components: {},
    props: {
        activeTabsCode: {
            type: String,
            default: '1'
        }
    },
    data() {
        return {
            tabs: [{
                text: 'AI角色聊天',
                code: '1',
                path: '/index'
            },
            {
                text: '智能聊天',
                code: '3',
                path: '/aiChat'
            }, {
                text: '角色管理',
                code: '2',
                path: '/roleManage'
            }]
        };
    },
    computed: {},
    mounted() { },
    methods: {
        tabChange(path) {
            this.$router.replace(path);
        },
        operateHandle(code) {
            if (code === 'logout') {
                localStorage.removeItem('token');
                this.$router.replace('/login');
            }
        }
    }
};
</script>

<style scoped lang="less">
.tabs {
    position: relative;
    height: 54px;
    font-size: 16px;
    box-shadow: 0px 1px 6px rgba(108, 105, 105, 0.5);
    & > div {
        margin-left: 40px;
        &:nth-child(1) {
            margin-left: 0;
        }
        position: relative;
        cursor: pointer;
        line-height: 2;
        &.active {
            position: relative;
            color: @Primary;
            font-weight: bold;
            &::after {
                content: '';
                width: 20px;
                height: 3px;
                position: absolute;
                left: 50%;
                -webkit-transform: translateX(-50%);
                transform: translateX(-50%);
                bottom: -4px;
                margin-left: -10px;
                background-color: @Primary;
                border-radius: 2px;
                -webkit-transform: skewX(-45deg);
                transform: skewX(-45deg);
            }
        }
    }
    .operate {
        position: absolute;
        right: 30px;
        top: 50%;
        transform: translateY(-50%);
        i {
            font-size: 22px;
        }
    }
}
</style>
